/**
 * 
 */
package com.lehecai.core.lottery;

import com.lehecai.core.IntegerBeanLabelItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qatang
 * 竞彩冠亚军即时SP值
 */
public class JcgyjSPType extends IntegerBeanLabelItem {


	private static final long serialVersionUID = 2465840431256917709L;

	private static final Logger logger = LoggerFactory.getLogger(JcgyjSPType.class.getName());

	private static List<JcgyjSPType> items = new ArrayList<JcgyjSPType>();

	private static Map<LotteryType, List<JcgyjSPType>> lotteryItemsMap = new HashMap<LotteryType, List<JcgyjSPType>>();

	protected JcgyjSPType(String name, int value) {
		this(name, value, null);
	}

	protected JcgyjSPType(String name, int value, LotteryType lotteryType) {
		super(JcgyjSPType.class.getName(), name, value);
		items.add(this);
		
		if (lotteryType != null) {
			synchronized(this) {
				List<JcgyjSPType> lotteryItems = lotteryItemsMap.get(lotteryType);
				if (lotteryItems == null) {
					lotteryItems = new ArrayList<JcgyjSPType>();
					lotteryItemsMap.put(lotteryType, lotteryItems);
				}
				lotteryItems.add(this);
			}
		}
	}
	
	public static JcgyjSPType getItem(int value){
		try {
			return (JcgyjSPType) JcgyjSPType.getResult(JcgyjSPType.class.getName(), value);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	}
	
	public static List<JcgyjSPType> getItems() {
		return items;
	}
	
	public static List<JcgyjSPType> getItems(LotteryType lotteryType) {
		return lotteryItemsMap.get(lotteryType);
	}
	
	private static Map<JcgyjSPType, String> lotteryConstantMap = new HashMap<JcgyjSPType, String>();
	
	public static String getLotteryConstant(JcgyjSPType spType) {
		return lotteryConstantMap.get(spType);
	}
	//猜冠亚军
	public static final JcgyjSPType GYJ = new JcgyjSPType("冠亚军", 54, LotteryType.JCGYJ);
	
	@Override
	public String toString() {
		return this.name;
	}

	static {
		lotteryConstantMap.put(JcgyjSPType.GYJ, LotteryConstant.JCGYJ_VALUE);
	}
	
}
